import { GameObjects, Math, Scene } from 'phaser';
import { blockSize, gridSize } from '@/pages/game/snake/scenes';

export class Food extends GameObjects.Image {
  total = 0;

  constructor(scene: Scene, x: number, y: number, key: string) {
    super(scene, x, y, key);
    this.setTexture(key);
    this.setPosition(x * blockSize, y * blockSize);
    this.setOrigin(0);
    scene.children.add(this);
  }

  eat() {
    const x = Math.Between(0, gridSize.x);
    const y = Math.Between(0, gridSize.y);
    this.setPosition(x * blockSize, y * blockSize);
    this.total++;
  }
}
